<?php
/**
 * 短信宝短信发送接口
 * User: yu
 * Date: 16-11-14
 * Time: 下午4:19
 */

namespace utils\sms;

use herosphp\core\Loader;

Loader::import('utils.sms.Provider');

class SmsBaoProvider implements Provider
{
    private $user = null;//短信平台帐号
    private $pass = null;//短信平台密码
    private $key = null;
    private $sign = null;
    private $authed = false;

    public function auth($user, $pass, $key, $sign)
    {
        $this->user = $user;
        $this->pass = $pass;
        $this->key = $key;
        $this->sign = $sign;
        $this->authed = true;
    }


    /**
     * 发送短信
     * @param $content //要发送的短信内容
     * @param $mobile //要发送短信的手机号码
     */
    public function send($mobile,$content)
    {
        if ($this->authed != true) {

            return false;
        }

        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );
        $smsapi = "http://api.smsbao.com/";
        $pass = md5($this->pass); //短信平台密码

        $sendurl = $smsapi . "sms?u=" . $this->user . "&p=" . $pass . "&m=" . $mobile . "&c=" . urlencode($content);
        $result = file_get_contents($sendurl);
        return $statusStr[$result];


    }


}